home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / BuildingBlocks / HandleObjectOwner.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  1.4 KB  |  63 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        HandleObjectOwner.h
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef    __HANDLEOBJECTOWNER__
  15. #define    __HANDLEOBJECTOWNER__
  16.  
  17. #ifndef    __HANDLEOBJECT__
  18. #include "HandleObject.h"
  19. #endif
  20.  
  21. #pragma push
  22. #pragma segment HandleObject
  23.  
  24. /***********************************|****************************************
  25.  
  26.     this is a class which can be instantiated on the stack that owns a
  27.     handle object, that is when the THandleObjectOwner is deleted upon
  28.     exit of its scope the owned handle object is deleted automatically
  29.  
  30.     for example:
  31.  
  32.     void foo ()
  33.     {
  34.         TVirtualFile* file = new TSomeVirtualFile;
  35.         THandleObjectOwner fileOwner ( file );
  36.  
  37.         if ( noErr != file->Write ( "hello" ) )
  38.             return;
  39.  
  40.         if ( noErr != file->Write ( " world" ) )
  41.             return;
  42.  
  43.         // the fileOwner automatically deletes the virtual file
  44.         // upon exit of the Foo () function, thus allowing the
  45.         // programmer to worry less about memory management.
  46.     }
  47.  
  48. ***********************************|****************************************/
  49.  
  50. class THandleObjectOwner
  51. {
  52. public:        THandleObjectOwner ( THandleObject* object );
  53.             ~THandleObjectOwner ();
  54.  
  55. private:    THandleObject*            fObject;
  56. };
  57.  
  58. /***********************************|****************************************/
  59.  
  60. #pragma pop
  61.  
  62. #endif    // __HANDLEOBJECTOWNER__
  63.